<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择订单关联产品')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>产品名称：</p>
                                <input type="text" id="productName"  name="params[productName]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "crm/orderProduct";
        var orderId=[[${orderId}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                queryParams: queryParams,
		        sortName: "createTime",
		        sortOrder: "desc",
		        clickToSelect: true,
                modalName: "订单关联产品信息",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'orderProductId', 
                    title : '订单产品ID',
                    visible: false
                },
                {
                    field : 'orderId', 
                    title : '订单id',
                    visible: false
                },
                {
                    field : 'productId', 
                    title : '产品id',
                    visible: false
                },
                {
                    field : 'product.productName', 
                    title : '产品名称',
		            sortable: true
                },
                {
                    field : 'productCount', 
                    title : '订购数量',
		            sortable: true
                },
                {
                    field : 'order.orderName', 
                    title : '订单主题',
		            sortable: true
                },
                {
                    field : 'order.customer.customerName', 
                    title : '成交客户',
		            sortable: true
                },
                {
                    field : 'shipStatus', 
                    title : '发货状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(shipStatusDatas, value);
                    },
                    visible: false,
		            sortable: true
                },
                {
                    field : 'shipNo', 
                    title : '发货单号',
                    visible: false,
		            sortable: true
                }]
            };
            $.table.init(options);
        });
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			search.orderId = orderId;
			return search;
		}

		
		/* 选择订单关联产品 */
		function submitHandler() {
			var productIds = $.table.selectFirstColumns();
			var productNames = $.table.selectColumns("productName");
			if (productIds.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			$.modal.close();
			for(var i=0;i<productIds.length;i++){
				parent.addColumnOrder(productIds[i],productNames[i]);
				}
		}
    </script>
</body>
</html>